package com.polaris.live.popup

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.StringUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.adapter.MagicLampRewardAdapter
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.PopupMagicLampWinRewardBinding
import com.polaris.live.resp.back_resp.PayerLampLotteryResp
import com.polaris.live.translation.R.string

/**
 * MagicLampWinRewardPopup 中奖情况弹窗
 * @author Created by 天晴 on 2024/11/25 10:28
 * @since 1.0.0
 **/
class MagicLampWinRewardPopup(
    context: Context,
    val data: PayerLampLotteryResp,
) : CenterPopupView(context) {

    override fun getImplLayoutId(): Int {
        return R.layout.popup_magic_lamp_win_reward
    }

    private lateinit var mBinding: PopupMagicLampWinRewardBinding

    private val mAdapter: MagicLampRewardAdapter by lazy {
        MagicLampRewardAdapter()
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupMagicLampWinRewardBinding.bind(popupImplView)
        mBinding.okBtn.setOnSingleClickListener {
            dismiss()
        }
        if (data.rewards.isNotEmpty()) {
            mBinding.tvTips.text =
                StringUtils.getString(string.you_have_received_magic_lamp_reward)
            mBinding.emptyImg.visibility = View.GONE
            mBinding.recycler.visibility = View.VISIBLE
            mBinding.recycler.apply {
                layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                adapter = mAdapter
                itemAnimator = null
            }
            mAdapter.setList(data.rewards)
        } else {
            mBinding.tvTips.text =
                StringUtils.getString(string.you_almost_won_the_prize)
            mBinding.emptyImg.visibility = View.VISIBLE
            mBinding.recycler.visibility = View.GONE
        }

    }

    override fun getMaxWidth(): Int {
        return ScreenUtils.getScreenWidth()
    }

    override fun getPopupWidth(): Int {
        return ScreenUtils.getScreenWidth()
    }

    companion object {

        fun show(
            context: Context,
            data: PayerLampLotteryResp,
        ) {

            XPopup.Builder(context)
                .isViewMode(false)
                .hasShadowBg(true)
                .moveUpToKeyboard(false)
                .isDestroyOnDismiss(true)
                .asCustom(MagicLampWinRewardPopup(context, data))
                .show()
        }
    }

}